#include <stdlib.h>
#include <SDL2/SDL.h>
int
main(int argc, char **argv)
{
	if(SDL_Init(SDL_INIT_EVERYTHING))
		fprintf(stderr, "Error: %s :(\n", SDL_GetError());

	SDL_Window *window;
	
	if(!(window = SDL_CreateWindow("CodePorts!", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL)))
		fprintf(stderr, "Error: %s :(\n", SDL_GetError());

	SDL_Renderer *renderer;

	if(!(renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)))
		fprintf(stderr, "Error: %s :(\n", SDL_GetError());
	
	SDL_Surface *surface;

	if(!(surface = SDL_LoadBMP(argv[1])))
		fprintf(stderr, "Error: %s :(\n", SDL_GetError());

	SDL_Texture *texture;

	if(!(texture = SDL_CreateTextureFromSurface(renderer, surface)))
		fprintf(stderr, "Error: %s :(\n", SDL_GetError());

	SDL_Event e;
	int quit = 0;
	while(!quit)
	{
		while(SDL_PollEvent(&e))
		{
			if(e.type == SDL_QUIT || e.type == SDL_KEYDOWN || e.type == SDL_MOUSEBUTTONDOWN)
				quit = 1;
		}
		SDL_RenderClear(renderer);
		SDL_RenderCopy(renderer, texture, NULL, NULL);
		SDL_RenderPresent(renderer);
	}

	SDL_FreeSurface(surface);
	SDL_DestroyTexture(texture);
	SDL_DestroyRenderer(renderer);
	SDL_DestroyWindow(window);

	SDL_Quit();

	return EXIT_SUCCESS;
}
